package com.iss.dao;

import com.iss.model.Room;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class RoomDAO implements BasicDAO<Room> {
    @Override
    public boolean insert(Room room) {
        return false;
    }

    @Override
    public boolean update(Room room) {
        return false;
    }

    @Override
    public boolean delete(Room room) {
        return false;
    }

    @Override
    public List<Room> select() {
        ResultSet rs = dbUtil.query("SELECT * FROM room;");
        ArrayList<Room> rooms = new ArrayList<>();
        try{
        while (rs.next()){
            rooms.add(getRoomFromRs(rs));
        }}catch (SQLException e) {
            e.printStackTrace();
        }

        return rooms;
    }

    private Room getRoomFromRs(ResultSet rs) {

        Room room = new Room();
        try {
            room.setRoomId(rs.getInt("roomid"));
            room.setRoomNO(rs.getString("roomNO"));
            room.setPrice(rs.getFloat("price"));
        } catch (SQLException e) {
            e.printStackTrace();
        }

        return room;
    }
}
